package tasksimulator;

import java.util.ArrayList;

/**
 *
 * @author Jonas
 */
public class TaskSimulator {

    public static long seed = 12345678;
    public int threads = 1;
    public int amountOfTasks = 500;
    public int taskMeanTime = 30;
    public ArrayList<TaskRunner> runners;

    public TaskSimulator(int threads, int startingKey, int amountOfTasks, int taskMeanTime) {
        this.threads = threads;
        Task.setStartingKey(startingKey);
        this.amountOfTasks = amountOfTasks;
        this.taskMeanTime = taskMeanTime;
        runners = new ArrayList<TaskRunner>();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int threads = Integer.valueOf(args[0]);
        int startingKey = Integer.valueOf(args[1]);
        int amountOfTasks = Integer.valueOf(args[2]);
        int taskMeanTime = Integer.valueOf(args[3]);
        String database = args[4];
        if(database.equalsIgnoreCase("postgres")) {
            Databaser.database = Databaser.DB.POSTGRES;
            Databaser.PGHOST = args[5];
        } else {
            Databaser.database = Databaser.DB.CASSANDRA;
        }

        TaskSimulator ts = new TaskSimulator(threads, startingKey, amountOfTasks, taskMeanTime);
        ts.go();
    }

    private void go() {
        for (int i = 0; i < threads; i++) {
            TaskRunner r = new TaskRunner(taskMeanTime, amountOfTasks);
            this.runners.add(r);
            r.start();
        }
    }
}
